package com.hysf.Interceptor;

import com.hysf.entity.Category;
import com.hysf.entity.Good;
import com.hysf.entity.Product;
import com.hysf.service.CategoryService;
import com.hysf.service.GoodService;
import com.hysf.service.ProductService;
import com.hysf.service.impl.CategoryServiceImpl;
import com.hysf.service.impl.GoodServiceImpl;
import com.hysf.service.impl.ProductServiceImpl;

import javax.servlet.*;
import java.io.IOException;
import java.util.List;
/**
 *
 * @Description:
 *
 * @Author: 石涛
 * @Date: 2024/4/9 10:51
 **/
public class MyFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // 初始化方法，在过滤器创建时调用
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        // 实际过滤逻辑在这里
        // 可以在这里添加你的代码，比如检查用户是否登录
        GoodService service =new GoodServiceImpl();
        GoodService service2 =new GoodServiceImpl();
        GoodService service3 =new GoodServiceImpl();
        GoodService service4 =new GoodServiceImpl();
        List<Good> goods = service.HEfind();
        request.setAttribute("goods", goods);
        List<Good> goods2 = service2.Bookfind();
        request.setAttribute("goods2", goods2);
        List<Good> goods3 = service3.Phonefind();
        request.setAttribute("goods3", goods3);
        List<Good> goods4 = service4.DGfind();
        request.setAttribute("goods4", goods4);


        CategoryService service5 = new CategoryServiceImpl();
        List<Category> categorys = service5.CategoryfindAll();
        request.setAttribute("categorys", categorys);
        // 继续过滤器链

        ProductService service6 =new ProductServiceImpl();
        List<Product> products6 = service6.hotfind();
        request.setAttribute("products6",products6);

        ProductService service7 =new ProductServiceImpl();
        List<Product> products7 = service7.newfind();
        request.setAttribute("products7",products7);

        chain.doFilter(request, response);

    }

    @Override
    public void destroy() {
        // 销毁方法，在过滤器销毁时调用
    }
}
